package com.ad.pet.app.main.adapter;

import android.app.Activity;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ad.pet.MainActivity;
import com.ad.pet.R;
import com.ad.pet.app.Navigation;
import com.ad.pet.common.data.utils.SpUtil;
import com.ad.pet.common.data.utils.glide.GlideUtil;
import com.ad.pet.constant.Constant;
import com.ad.pet.models.remote.home.HomeProduceItem;

import java.util.List;

/**
 * 商城-商城里面商品子页面适配器
 * Created by SEELE on 2018/3/27.
 */

public class HomeTypeItemAdapter extends BaseQuickAdapter<HomeProduceItem, BaseViewHolder> {

    public HomeTypeItemAdapter(int layout, @Nullable List<HomeProduceItem> data) {
        super(layout, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final HomeProduceItem item) {
        helper.setText(R.id.tv_title, item.getTitle()).
                setText(R.id.tv_price, SpUtil.getInstance().getString(Constant.CURRENCY_LABEL,"US $") + item.getPrice());
        ImageView view = helper.getView(R.id.iv_pic);
        GlideUtil.load(mContext, item.getPic_path(), view);
        TextView tvOrginal = helper.getView(R.id.tv_old_price);
        tvOrginal.setText(TextUtils.isEmpty(item.getOrg_price())?"":SpUtil.getInstance().getString(Constant.CURRENCY_LABEL,"US $") + item.getOrg_price());
        tvOrginal.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        ImageView ivDiscount = helper.getView(R.id.iv_photo_discount);
        if (ivDiscount != null) {
            if (TextUtils.isEmpty(item.getDiscount())) {
                ivDiscount.setVisibility(View.GONE);
            } else {
                ivDiscount.setVisibility(View.VISIBLE);
                GlideUtil.load(mContext, item.getDiscount(), ivDiscount);
            }
        }
        helper.getView(R.id.linear_out).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Navigation.goCommonWebView((Activity) mContext, mContext.getString(R.string.good_detail), item.getUrl(), false, MainActivity.REQUEST_GO_MALL);
            }
        });

    }
}
